package com.abaaba.project2.controller;

import com.abaaba.project2.bean.Issue;
import com.abaaba.project2.bean.bo.AdminIssueBo;
import com.abaaba.project2.bean.vo.AdminIssueVo;
import com.abaaba.project2.bean.vo.BaseRespVo;
import com.abaaba.project2.service.AdminIssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/issue")
public class AdminIssueController {
    @Autowired
    AdminIssueService adminIssueService;

    @RequestMapping("/list")
    public BaseRespVo getIssueList(Integer page, Integer limit, String question, String sort, String order) {
        AdminIssueVo adminIssueVo = adminIssueService.getIssueList(page, limit, question, sort, order);
        return BaseRespVo.ok(adminIssueVo);
    }

    @RequestMapping("/delete")
    public BaseRespVo deleteIssue(@RequestBody Issue issue) {
        int affectedRows = adminIssueService.deleteIssue(issue);
        return BaseRespVo.ok();
    }

    @RequestMapping("/create")
    public BaseRespVo createIssue(@RequestBody AdminIssueBo adminIssueBo) {
        Issue issue = adminIssueService.createIssue(adminIssueBo);
        return BaseRespVo.ok(issue);
    }

    @RequestMapping("/update")
    public BaseRespVo updateIssue(@RequestBody Issue issue) {
        Issue issue1 = adminIssueService.updateIssue(issue);
        return BaseRespVo.ok(issue1);
    }
}
